import pasteboard from '@ohos.pasteboard';
export default {
    data: {
        title: 'World'
    },
    createPlainTextData(){
        var pasteData = pasteboard.createPlainTextData("content");
        let data=pasteData.getPrimaryText()
        console.log('剪切板数据:',data)
    },
    getSystemPasteboard(){
        var systemPasteboard = pasteboard.getSystemPasteboard();
//        callback
        systemPasteboard.getPasteData((error, pasteData) => {
            if (error) {
                console.error('failed to getPasteData because ' + error.message);
                return;
            }
            var text = pasteData.getPrimaryText();
        });
//        promise
        systemPasteboard.getPasteData()
            .then((pasteData) => {
            var text = pasteData.getPrimaryText();
        }).catch((error) => {
            console.error('failed to getPasteData because ' + err.message);
        })
    },
    setSystemPasteboard(){
        var systemPasteboard = pasteboard.getSystemPasteboard();
        var pasteData = pasteboard.createPlainTextData("content");
//        callback
        systemPasteboard.setPasteData(pasteData, (error, data) => {
            if (error) {
                console.error('failed to setPasteData because ' + error.message);
                return;
            }
            console.info('success to setPasteData:' + data);
        });
//        promise
//        systemPasteboard.setPasteData(pasteData)
//            .then((data) => {
//            console.info('success to setPasteData:' + data);
//        }).catch((error) => {
//            console.error('failed to setPasteData because ' + error.message);
//        })
    }
}
